from django.urls import reverse
from rest_framework.test import APIClient
from django.db.models import Sum
from play.models import Play
from video.models import Videos
from django.test import TestCase
from user.models import UserProfile
from notifications_center.models import Notification
from column.models import Column


class TestNotificationViewSet(TestCase):
    def setUp(self):
        self.client = APIClient()
        self.user1 = UserProfile.objects.create_user(id=1, username='testuser1', password='123456456')
        self.user2 = UserProfile.objects.create_user(id=2, username='testuser2', password='123456456')
        self.user3 = UserProfile.objects.create_user(id=3, username='testuser3', password='123456456')
        self.video1 = Videos.objects.create(vid=1, title='test1', duration=10, mup=self.user1, type='1')
        self.video2 = Videos.objects.create(vid=2, title='test2', duration=10, mup=self.user1, type='2')
        self.video3 = Videos.objects.create(vid=3, title='test3', duration=10, mup=self.user1, type='2')
        self.play1 = Play.objects.create(pid=1, video=self.video1, count=6, user=self.user1)
        self.play2 = Play.objects.create(pid=2, video=self.video1, count=55, user=self.user2)
        self.play3 = Play.objects.create(pid=3, video=self.video2, count=10, user=self.user3)
        self.column1 = Column.objects.create(coid=1, mup=self.user2)
        self.column2 = Column.objects.create(coid=2, mup=self.user2)
        self.msg1 = Notification.objects.create(
            sender=self.user1,
            customer=self.user2,
            recipient_id=2,
            actor_content_type_id=1,
            category=Notification.Categories.REPLY,
            root_parent_content="Original content of the root",
            direct_parent_content="Direct parent content",
            checked=False
        )

        self.msg2 = Notification.objects.create(
            sender=self.user2,
            customer=self.user3,
            recipient_id=3,
            actor_content_type_id=2,
            category=Notification.Categories.MENTION,
            root_parent_content="Some other root content",
            direct_parent_content="Mentioned in the direct parent content",
            checked=True
        )

        self.msg3 = Notification.objects.create(
            sender=self.user3,
            customer=self.user1,
            recipient_id=1,
            actor_content_type_id=3,
            category=Notification.Categories.LIKE,
            root_parent_content="Liked content root",
            direct_parent_content="Liked direct parent content",
            checked=False
        )

        self.msg4 = Notification.objects.create(
            sender=self.user3,
            customer=self.user1,
            recipient_id=1,
            actor_content_type_id=4,
            category=Notification.Categories.LIKE,
            root_parent_content="Liked content root",
            direct_parent_content="Liked direct parent content",
            checked=True
        )

        self.msg5 = Notification.objects.create(
            sender=self.user3,
            customer=self.user1,
            recipient_id=1,
            actor_content_type_id=5,
            category=Notification.Categories.MENTION,
            root_parent_content="Liked content root",
            direct_parent_content="Liked direct parent content",
            checked=False
        )

    def test_get_checked_message_num_E(self):
        url = reverse('get_checked_message_num', kwargs={'user': 1})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['all_num'], 2)

    def test_get_checked_message_num_NE(self):
        url = reverse('get_checked_message_num', kwargs={'user': 1})
        responce = self.client.get(url)
        data = responce.json()
        self.assertEqual(data['like_num'], 1)

    def test_send_comment1(self):
        url = reverse('notifications_comment')
        responce = self.client.post(url, {'actor': 1, 'recipient': 2, 'description': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_comment2(self):
        url = reverse('notifications_comment')
        responce = self.client.post(url, {'actor': 1, 'recipient': 3, 'description': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_comment_comment1(self):
        url = reverse('notifications_comment_comment')
        responce = self.client.post(url,
                                    {'actor': 1, 'recipient': 2, 'description': 'hhhh', 'root_parent_content': 'hhhh',
                                     'direct_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_comment_comment2(self):
        url = reverse('notifications_comment_comment')
        responce = self.client.post(url,
                                    {'actor': 1, 'recipient': 3, 'description': 'hhhh', 'root_parent_content': 'hhhh',
                                     'direct_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_like1(self):
        url = reverse('notifications_like')
        responce = self.client.post(url, {'actor': 1, 'recipient': 2, 'root_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_like2(self):
        url = reverse('notifications_like')
        responce = self.client.post(url, {'actor': 1, 'recipient': 3, 'root_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_at(self):
        url = reverse('notifications_comment_comment')
        responce = self.client.post(url,
                                    {'actor': 1, 'recipient': 2, 'description': 'hhhh', 'root_parent_content': 'hhhh',
                                     'direct_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_at2(self):
        url = reverse('notifications_comment_comment')
        responce = self.client.post(url,
                                    {'actor': 1, 'recipient': 3, 'description': 'hhhh', 'root_parent_content': 'hhhh',
                                     'direct_parent_content': 'hhhh'})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_reviewing_passed(self):
        url = reverse('send_video_reviewing_passed')
        responce = self.client.post(url, {'video': 1})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_reviewing_passed2(self):
        url = reverse('send_video_reviewing_passed')
        responce = self.client.post(url, {'video': 2})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_reviewing_not_passed(self):
        url = reverse('send_video_reviewing_not_passed')
        responce = self.client.post(url, {'video': 1})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_reviewing_not_passe2(self):
        url = reverse('send_video_reviewing_not_passed')
        responce = self.client.post(url, {'video': 2})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_change(self):
        url = reverse('send_video_change')
        responce = self.client.post(url, {'video': 1, 'type': '1'})
        self.assertEqual(responce.status_code, 200)

    def test_send_video_change2(self):
        url = reverse('send_video_change')
        responce = self.client.post(url, {'video': 2, 'type': '2'})
        self.assertEqual(responce.status_code, 200)

    def test_sentFan(self):
        url = reverse('sentFan')
        responce = self.client.post(url, {'mup': 1, 'fan': 2})
        self.assertEqual(responce.status_code, 200)

    def test_sentFan2(self):
        url = reverse('sentFan')
        responce = self.client.post(url, {'mup': 1, 'fan': 3})
        self.assertEqual(responce.status_code, 200)

    def test_send_column_created(self):
        url = reverse('send_column_created')
        responce = self.client.post(url, {'coid': 1})
        self.assertEqual(responce.status_code, 200)

    def test_send_column_created2(self):
        url = reverse('send_column_created')
        responce = self.client.post(url, {'coid': 2})
        self.assertEqual(responce.status_code, 200)

    def test_send_column_change(self):
        url = reverse('send_column_change')
        responce = self.client.post(url, {'column': 1, 'type': 0})
        self.assertEqual(responce.status_code, 200)

    def test_send_column_change2(self):
        url = reverse('send_column_change')
        responce = self.client.post(url, {'column': 2, 'type': 1})
        self.assertEqual(responce.status_code, 200)